package com.technician.common;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.technician.model.enums.HttpStatusEnum;
import lombok.Data;

@JsonInclude(JsonInclude.Include.NON_NULL)
@Data
public class ResponseResult<T> {

    /**
     * 状态码
     */
    private Integer code;

    /**
     * 错误提示信息
     */
    private String msg;

    /**
     * 查询到的数据
     */
    private T data;

    /**
     * 返回错误信息
     * @param code
     * @param msg
     */
    public ResponseResult(Integer code,String msg){
        this.code = code;
        this.msg = msg;
    }

    /**
     * 返回数据
     * @param code
     * @param data
     */
    public ResponseResult(Integer code,T data){
        this.code = code;
        this.data = data;
    }

    public ResponseResult(Integer code,String msg,T data){
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

    public static ResponseResult success(HttpStatusEnum httpStatusEnum,Object data){
        ResponseResult<Object> responseResult = new ResponseResult<>(httpStatusEnum.getCode(), httpStatusEnum.getMessage(), data);
        return responseResult;
    }
    public static ResponseResult success(HttpStatusEnum httpStatusEnum){
        return success(httpStatusEnum,null);
    }

    public static ResponseResult success(){
        return success(HttpStatusEnum.SUCCESS_RESPONSE,null);
    }
    public static ResponseResult success(Object data){
        return success(HttpStatusEnum.SUCCESS_RESPONSE,data);
    }

    public static ResponseResult success(Integer code,String msg,Object data){
        ResponseResult<Object> responseResult = new ResponseResult<>(code, msg, data);
        return responseResult;
    }
    public static ResponseResult success(Integer code,String msg){
        return success(code,msg,null);
    }


    public static ResponseResult error(HttpStatusEnum httpStatusEnum,Object data){
        ResponseResult<Object> responseResult = new ResponseResult<>(httpStatusEnum.getCode(), httpStatusEnum.getMessage(), data);
        return responseResult;
    }
    public static ResponseResult error(HttpStatusEnum httpStatusEnum){
        return error(httpStatusEnum,null);
    }

    public static ResponseResult error(){
        return error(HttpStatusEnum.ERROR_RESPONSE,null);
    }

    public static ResponseResult error(Integer code,String msg,Object data){
        ResponseResult<Object> responseResult = new ResponseResult<>(code, msg, data);
        return responseResult;
    }
    public static ResponseResult error(Integer code,String msg){
        return error(code,msg,null);
    }
}